<script setup>
import {artGetChannelsService} from '@/api/article'
import {ref} from 'vue'

// defineProps用props来接收父亲传来的值
defineProps({
    modelValue:{
        type:[Number,String]
    },
    width:{
        type: String,
        default: '100%' // 默认宽度
    }
})

// defineEmits用emit传值给父亲
const emit = defineEmits(['update:modelValue'])
const channelList = ref([])


const getChannelList =async() => {
    const res = await artGetChannelsService()
    channelList.value=res.data.data
    console.log(channelList.value);
    
}
getChannelList()
</script>
<template>
    <el-select 
    :modelValue="modelValue"
    @update:modelValue="emit('update:modelValue',$event)"
     :style="{width}"
     >
        <!-- label是展示给用户看的，value是提交给后台的 -->
        <el-option v-for="channel in channelList" 
        :key="channel.id"
        :label="channel.cate_name" 
        :value="channel.id"
        ></el-option>
        <el-option label="体育" value="137"></el-option>
    </el-select>
</template>